﻿
    using Chain.BLL;
    using System;
    using System.Data;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public partial class WeiXinMenuManager : PageBase
    {

        private int menuFirst;

        private WeiXinMenu WeiXinMenuBll = new WeiXinMenu();

        private void BindMenuFirst()
        {
            DataTable dt = this.WeiXinMenuBll.GetMenuParentInfo().Tables[0];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (Convert.ToInt32(dt.Rows[i]["childNum"]) < 5)
                {
                    this.sltMenuType.Items.Add(new ListItem(dt.Rows[i]["MenuName"].ToString(), dt.Rows[i]["MenuID"].ToString()));
                }
            }
        }

        private void BindReplyRule()
        {
            DataTable dt = new Chain.BLL.WeiXinRule().GetList("").Tables[0];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                this.sltReply.Items.Add(new ListItem(dt.Rows[i]["RuleDesc"].ToString(), dt.Rows[i]["RuleNUmber"].ToString()));
            }
        }

        protected string GetMenuName(object objMenuName, object objparentMenuID)
        {
            if (objparentMenuID.ToString() != "0")
            {
                return ("----" + objMenuName);
            }
            return objMenuName.ToString();
        }

        protected string GetMenuTypeName(object objMenuType)
        {
            switch (Convert.ToInt32(objMenuType))
            {
                case 0:
                    return "菜单类型";

                case 1:
                    return "按钮类型";

                case 2:
                    return "链接类型";
            }
            return "未知类型";
        }

        private void IsShowAddMenuButtom(int menuCount)
        {
            if (menuCount >= 0x12)
            {
                this.btnAddMenu.Disabled = true;
            }
        }

        protected string MenuDel(object objLevel, object objMenuID, object objMenuName)
        {
            string returnStr = string.Empty;
            if (((!(objLevel.ToString() == "0") && !(objMenuID.ToString() == "4")) && (!(objMenuID.ToString() == "5") && !(objMenuID.ToString() == "6"))) && ((!(objMenuID.ToString() == "8") && !(objMenuID.ToString() == "9")) && !(objMenuID.ToString() == "10")))
            {
                returnStr = string.Concat(new object[] { "<a href=\"javascript:menuDel(", objMenuID, ",'", objMenuName, "')\"><img src=\"../images/Gift/del.png\" alt=\"删除\" title=\"删除\" /></a>" });
            }
            return returnStr;
        }

        protected string MenuEdit(object objMenuID, object parentMenuID, object objMenuName, object objparentMenuID)
        {
            if ((((objMenuID.ToString() == "4") || (objMenuID.ToString() == "5")) || ((objMenuID.ToString() == "6") || (objMenuID.ToString() == "8"))) || ((objMenuID.ToString() == "9") || (objMenuID.ToString() == "10")))
            {
                return string.Concat(new object[] { "<a href=\"javascript:updateMenuFirstBySystem(", objMenuID, ",'", objMenuName, "','", objparentMenuID, "')\"><img src=\"../images/Gift/eit.png\" alt=\"编辑\" title=\"编辑\" /></a>" });
            }
            if (parentMenuID.ToString() == "0")
            {
                return string.Concat(new object[] { "<a href=\"javascript:updateMenuFirst(", objMenuID, ",'", objMenuName, "')\"><img src=\"../images/Gift/eit.png\" alt=\"编辑\" title=\"编辑\" /></a>" });
            }
            return string.Concat(new object[] { "<a href=\"javascript:updateMenuSecound(", objMenuID, ",'", objMenuName, "')\"><img src=\"../images/Gift/eit.png\" alt=\"编辑\" title=\"编辑\" /></a>" });
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                DataSet ds = this.WeiXinMenuBll.GetMenuAllInfo2();
                this.menuFirst = Convert.ToInt32(ds.Tables[1].Rows[0][0]);
                this.rpt_MenuManager.DataSource = ds.Tables[0];
                this.rpt_MenuManager.DataBind();
                this.IsShowAddMenuButtom(ds.Tables[0].Rows.Count);
                this.BindMenuFirst();
                this.BindReplyRule();
            }
        }
    }


